/*
 * SOUND.c
 *
 * Created: 12.11.2012 17:08:36
 *  Author: mariuvi
 */ 

#define F_CPU 8000000

#include <avr/io.h>
#include "definitions.h"

void SOUND_init()
{	
	//Fast PWM mode, ICR1 as TOP
	BIT_SET(TCCR1B, WGM13);
	BIT_SET(TCCR1B, WGM12);
	BIT_SET(TCCR1A, WGM11);
	
	//Set clock prescaler to 1/8
	BIT_SET(TCCR1B, CS11);
	
	//Set the TOP value
	ICR1 = F_CPU/(8*50);
	
	//Clear OC1A on compare match
	BIT_SET(TCCR1A, COM1A1);
	
	//Set the pulse width to 1.5 ms (center)
	OCR1A = 1500;
	
	//Set OC1A as output
	BIT_SET(DDRB, PB5);
}
